import {express} from "express"
import {userRoute} from "api/user.route.js"
import {dotenv} from "dotenv"
import {bodyParser} from "body-parser"
import {mongoose} from "mongoose"
import {cors} from "cors"
import {MongoTopologyClosedError} from "mongdb"




const app = express()
dotenv.config()

mongoose.connect(process.env.DB_URL)

mongoose.connection.on("error", err => {
  console.log("mongodb connect failed")
})

mongoose.connection.on("connected", connected => {
  console.log("connected with mongodb")
})

app.use(bodyParser.json({}))
app.use(cors())
app.use("/user", userRoute)

// middleware 
app.use((req, res, next) => {
  res.status(404).json({
    error: "can not find this page"
  })
})

export app
